const Urllink = '/mock/';
const Mock = require('mockjs')
// 获取页面的tokin
const tokens = {
    admin: {
        token: "admin-token",
    },
    editor: {
        token: "editor-token",
    },
};
// 获取的用户信息
const users = {
    // 超级管理员
    "admin-token":{
        code: 1,
        data: {
            username: {
                introduction: "I am a super administrator",
                avatarstr:  "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
                growth: "30",
                integral: 6,
                nickname: "3dm_JH",
                uid: "12721363",
                vip_level: 0,
                name: "Super Admin",
            },
            // 用户的路由
            router: [
                // {
                //     path: "/putIn",
                //     component: "Layout",
                //     redirect: "/putIn/ad_putin",
                //     name: "Commodity",
                //     meta: { title: "投放管理", icon: "el-icon-s-marketing"  },
                //     children: [
                //         {
                //             path: "ad_putin",
                //             name: "ADputin",
                //             component: "",
                //             meta: { title: "广告投放管理",   },
                //         },
                //         {
                //             path: "material",
                //             name: "Material",
                //             component: "",
                //             meta: { title: "物料管理",    },
                //         },
                //     ],
                // },
                // {
                //     path: "/resources",
                //     component: "Layout",
                //     redirect: "/resources/code",
                //     name: "resources",
                //     meta: { title: "资源管理", icon: "el-icon-s-order"  },
                //     children: [
                //         {
                //             path: "code",
                //             name: "Code",
                //             component: "",
                //             meta: { title: "代码位管理",   },
                //         },
                //         {
                //             path: "Media",
                //             name: "Media",
                //             component: "",
                //             meta: { title: "媒体管理",   },
                //         },
                //     ],
                // },
                // {
                //     path: "/report",
                //     component: "Layout",
                //     redirect: "/report/report-zy",
                //     name: "report",
                //     meta: { title: "报告", icon: "el-icon-s-data"  },
                //     children: [
                //         {
                //             path: "report-zy",
                //             name: "ReportZy",
                //             component: "",
                //             meta: { title: "资源报告",  icon: "el-icon-s-data"   },
                //         },
                //     ],
                // },
                // {
                //     path: "/permission",
                //     component: "Layout",
                //     redirect: "/permission/accvip",
                //     name: "accvip",
                //     meta: { title: "账户与设置", icon: "el-icon-s-tools"  },
                //     children: [
                //         {
                //             path: "accvip",
                //             name: "Accvip",
                //             component: "",
                //             meta: { title: "账户与会员管理",  },
                //         },
                //         {
                //             path: "operateLog",
                //             name: "OperateLog",
                //             component: "",
                //             meta: { title: "操作日志",   },
                //         },
                //     ],
                // },
            ],
            // 用户的权限
            perms: [
                "sys:product:edit", //商品编辑
                "sys:product:delete", //商品删除
                "sys:product:search", //商品搜索
                "sys:product:add", //商品增加
                "sys:role:edit", //角色编辑
                "sys:role:delete", //角色删除
                "sys:role:search", //角色搜索
                "sys:role:add", //角色增加
                "sys:role:cancel", //角色权限修改取消
                "sys:role:comfirm", //角色权限修改确定
                "sys:adminlist:edit", //用户编辑
                "sys:adminlist:delete", //用户删除
                "sys:adminlist:search", //用户搜索
                "sys:adminlist:add", //用户增加
                "sys:adminlist:moredelete", //用户批量删除
                "sys:menu:edit", //菜单编辑
                "sys:menu:delete", //菜单删除
                "sys:menu:search", //菜单搜索
                "sys:menu:add", //菜单增加
            ],
        },
    },
    // 子用户
    "editor-token": {
        code: 1,
        data: {
            username: {
                introduction: "I am an editor",
                avatarstr:
                    "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
                growth: "30",
                integral: 6,
                nickname: "editor",
                uid: "12721363",
                vip_level: 0,
                name: "Normal Editor",
            },
            // 用户的路由
            router: [
                {
                    path: "/product",
                    component: "Layout",
                    name: "Commodity",
                    meta: { title: "商品", icon: "el-icon-notebook-2" },
                    children: [
                        {
                            path: "index",
                            name: "Product",
                            component: "",
                            meta: { title: "商品列表" },
                        },
                    ],
                },
            ],
            // 用户的权限
            perms: [
                "sys:product:edit", //商品编辑
                "sys:product:delete", //商品删除
                "sys:product:search", //商品搜索
                // "sys:product:add",    //商品增加
            ],
        },
    }, 
};
// 获取所有的角色
const role = Mock.mock({
    'data|5': [{
      'id|+1':1,
      'name|1':["admin",'editor','角色2'],
      images:"@image('200x100', '#00405d', '#fff', 'Mock.js')",
      Price:"@float(60, 100, 3, 5)",
      remarks:'@cparagraph(1,2)',
      edit:false,
      'num|1-5':1,
      'eltree|2':[1,12],
      datatime:"@date('yyyy-MM-dd HH:mm:ss ')",

    }]
  })

// 菜单树
const findMenuTree= Mock.mock(
    {
      "code": 1,
      "msg": null,
      "data": [
        {
          id: 1,
          title:"首页",
          type:1,
          parentName:'',
          url:'',
          perms:'',
          sort:0,
           ico:'',
          children:[]
        },
        {
          id: 2,
          title:"系统管理",
          type:1,
          parentName:'',
          url:'',
          perms:'',
          sort:1,
          ico:'',
          children:[
            {
              id: 10,title:"角色管理",  type:2, parentName:'系统管理', url:'permission/role', perms:'',  sort:1,
              children: [
                { id:11, title:"搜索", type:3, parentName:'角色管理', url:'', perms:'sys:user:view', sort:1,},
                { id:12, title:"新增", type:3, parentName:'角色管理', url:'', perms:'sys:user:add', sort:2,},
              ]
            },
            {
              id: 20,title:"用户管理",  type:2, parentName:'系统管理', url:'permission/aminlist', perms:'',  sort:2,
              children: [
                { id: 21, title:"搜索", type:3, parentName:'用户管理', url:'', perms:'sys:user:view', sort:1,},
                { id: 22, title:"新增", type:3, parentName:'用户管理', url:'', perms:'sys:user:add', sort:2,},
              ]
            },
            {
              id:30,title:"菜单管理",  type:2, parentName:'系统管理', url:'permission/menu', perms:'',  sort:3,
              children: [
                { id: 31, title:"搜索", type:3, parentName:'菜单管理', url:'', perms:'sys:user:view', sort:1,},
                { id: 32, title:"新增", type:3, parentName:'菜单管理', url:'', perms:'sys:user:add', sort:2,},
              ]
            },
          ]
        },
      ]
    }
  )


module.exports = [
    // user 获取token
    {
        url: Urllink+"tokin",
        type: "post",
        response: (config) => {
            console.log( config.body)
            const { username } = config.body;
            const token = tokens[username];
            // mock error
            if (!token) {
              return {
                code: 60204,
                message: 'Account and password are incorrect.'
              }
            }
            return {
                code: 1,
                data: token,
            };
        },
    },
    // user  获取用户信息
    {
        url: Urllink+"login",
        type: "post",
        response: (config) => {
            const { token } = config.body;
            const info = users[token];
            // const info = users;
            // mock error
            if (!info) {
                return {
                    code: 50008,
                    message: "Login failed, unable to get user details.",
                };
            }
            return {
                code: 1,
                data: info,
            };
        },
    },
    // user 注销登录
    {
        url: Urllink+"logout",
        type: "post",
        response: () => {
            return {
                code: 1,
                data: "success",
            };
        },
    },
     // user 所有的角色
     {
        url: Urllink+"role",
        type: "post",
        response: ( ) => {
            return {
                code: 1,
                data: role
            };
        },
    },
    //获取用户菜单结合
   {
    url: Urllink+"findMenuTree",
    type: 'post',
    response: ( ) => {
      return {
        code: 1,
        data:findMenuTree
      }
    }
  },
];


